using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.WizardFramework;
using VSSDKAssist.Assets.CustomPages;
using VSSDKAssist.Recipes.Common.Editors;
using VSSDKAssist.Recipes.Common.Converters;
using EnvDTE;
using VSSDKAssist.Assets.Helpers;
using VSSDKAssist.Enums;
using VSSDKAssist.Recipes.Common.CustomPages;
using System.Globalization;
using VSSDKAssist.Recipes.Common.Helpers;

namespace VSSDKAssist.Recipes.ConfigureSplashAboutScreens
{
	/// <summary>
	/// Custom page for ConfigureSplashAboutScreensCP1 recipe
	/// </summary>
	public partial class ConfigureSplashAboutScreensCP1 : WizardPageBase
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="ConfigureSplashAboutScreensCP1"/> class.
		/// </summary>
		public ConfigureSplashAboutScreensCP1()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ConfigureSplashAboutScreensCP1"/> class.
		/// </summary>
		/// <param name="wizard">The <see cref="T:Microsoft.Practices.WizardFramework.WizardForm"/>that will host the new page.</param>
		public ConfigureSplashAboutScreensCP1(WizardForm wizard)
			: base(wizard)
		{
			InitializeComponent();
		}

		/// <summary>
		/// Gets or sets the name of the package product.
		/// </summary>
		/// <value>The name of the package product.</value>
		[RecipeArgument]
		public string PackageProductName
		{
			get { return (string)veProductName.Value; }
			set
			{
				if(value != null)
				{
					veProductName.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the package product details.
		/// </summary>
		/// <value>The package product details.</value>
		[RecipeArgument]
		public string PackageProductDetails
		{
			get { return (string)veProductDetails.Value; }
			set
			{
				if(value != null)
				{
					veProductDetails.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the package product version.
		/// </summary>
		/// <value>The package product version.</value>
		[RecipeArgument]
		public string PackageProductVersion
		{
			get { return (string)veProductVersion.Value; }
			set
			{
				if(value != null)
				{
					veProductVersion.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the site of the control.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="T:System.ComponentModel.ISite"></see> associated with the <see cref="T:System.Windows.Forms.Control"></see>, if any.</returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public override ISite Site
		{
			get
			{
				return base.Site;
			}
			set
			{
				base.Site = value;
				if(value != null)
				{
					this.veProductName.BeginInit();
					this.veProductName.ValueType = typeof(string);
					base.Site.Container.Add(veProductName);
					this.veProductName.EndInit();

					this.veProductVersion.BeginInit();
					this.veProductVersion.ValueType = typeof(string);
					base.Site.Container.Add(veProductVersion);
					this.veProductVersion.EndInit();

					this.veProductDetails.BeginInit();
					this.veProductDetails.ValueType = typeof(string);
					base.Site.Container.Add(veProductDetails);
					this.veProductDetails.EndInit();
				}
			}
		}

		private void veProductName_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			string productName = veProductName.Value as string;
			DictionaryService.SetValue("PackageProductName", productName);
		}

		private void veProductDetails_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			string productDetails = veProductDetails.Value as string;
			DictionaryService.SetValue("PackageProductDetails", productDetails);
		}

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Double.Parse(System.String,System.Globalization.NumberStyles)"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Double.Parse(System.String)"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
		private void veProductVersion_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			errorProvider.SetError(veProductVersion, string.Empty);

			try
			{
				double.Parse(veProductVersion.Value.ToString(), NumberStyles.Float);
				DictionaryService.SetValue("PackageProductVersion", veProductVersion.Value.ToString());
			}
			catch
			{
				DictionaryService.SetValue("PackageProductVersion", null);
				errorProvider.SetError(veProductVersion, Properties.Resources.InvalidValue);
			}
		}

		private void pctAboutScreen_Click(object sender, EventArgs e)
		{
			Bitmap bitmap = CustomPageHelper.GetBitmapResource("VSAbout");

			if(bitmap != null)
			{
				InfoForm infoForm = new InfoForm(bitmap);

				infoForm.ShowDialog();
			}
		}
	}
}